var config = require('../config/config')

var nodemailer = require('nodemailer')

var transporter = nodemailer.createTransport({
    host: "smtp.qq.com",
    secureConnection: true,
    port: 465,
    auth: {
        user: "1131029395@qq.com",
        pass: "ntxkwblzfkwdjagf"
    }
})

var sendEmail = function(toEmail, subject, html, callback) {
    var mailOptions = {
        from: config.siteEmail,
        to: toEmail,
        subject: subject,
        html: html
    }
    transporter.sendMail(mailOptions, (error, info) => {
        callback(error, info)
    });
}

module.exports = {
    getVerifyCode: function (email, code, callback) {
        var subject = '验证码： ' + code
        var html = '<h1>尊敬的用户</h1><p>您的验证码是：' + code + '，请妥善保管。</p>'
        sendEmail(email, subject, html, callback)
    }
}